<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragments :: head(~{::title})">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>详情页</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
  <!--文章的排版-->
  <link rel="stylesheet" href="../static/css/typo.css">
  <!--详情页的动态效果-->
  <link rel="stylesheet" href="../static/css/animate.css">
  <!--代码高亮-->
  <link rel="stylesheet" href="../static/lib/prism/prism.css">
  <!--自动生成目录-->
  <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css">
  <link rel="stylesheet" href="../static/css/me.css">
</head>
<body>

<!--导航-->
<nav th:replace="_fragments :: menu(1)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small" >

</nav>

<!--中间内容-->
<div  class="m-container m-padded-tb-big m-container-small animated fadeIn">
  <div class="ui container">
    <!--头部-->
    <div class="ui top attached segment">
      <div class="ui horizontal link list">
        <div class="item">
          <img src="https://unsplash.it/100/100?image=1005" th:src="${blog.user.avatar}" alt="" class="ui avatar image">
          <div class="content" ><a href="#" class="header" th:text="${blog.user.nickname}">高晗</a></div>
        </div>
        <div class="item">
          <i class="calendar icon"></i> <span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}">2017-10-01</span>
        </div>
        <div class="item">
          <i class="eye icon"></i> <span th:text="${blog.views}">2342</span>
        </div>
      </div>
    </div>
    <!--图片区域 attached是将头部与图片区域连接起来-->
    <div class="ui segment attached">
      <!--fluid作用是撑满segment的整个空间-->
      <img class="ui fluid image rounded" th:src="@{${blog.firstPicture}}" src="https://rong-1257752702.cos.ap-chengdu.myqcloud.com/%E5%8D%9A%E5%AE%A2%E9%A1%B9%E7%9B%AE/1.jpg">
    </div>
    <!--内容-->
    <div class="ui  segment attached padded">
      <!--right aligned basic 去边框，靠右-->
      <div class="ui right aligned basic segment">
        <div class="ui label orange" th:text="${blog.flag}">原创</div>
      </div>
      <!--标题-->
      <h2 class="ui center aligned header" th:text="${blog.title}"></h2>
      <br>
      <!--具体内容-->
      <div id="content" class="typo typo-selection js-toc-content m-padded-lr-responsive m-padded-tb-large" th:utext="${blog.content}">
      </div>
      <!--标签 pointing label 标签图片效果-->
      <div class="m-padded-lr-responsive">
        <div class="ui basic teal left pointing label" th:each="tag : ${blog.tags}" th:text="${tag.name}">方法论</div>
      </div>


      <div th:if="${blog.appreciation}">
        <!--赞赏-->
        <div id="reward" class="ui center aligned segment basic ">
          <button class="ui basic ui orange button circular   ">
            赞赏
          </button>
        </div>

        <!--js .class取的 pay-->
        <div class="ui pay flowing popup transition hidden">
          <div class="ui orange basic label">
            <div class="ui images">
              <div class="image">
                <!--rounded bordered 是边线和圆角-->
                <img class="ui image rounded bordered" th:src="@{/images/weixin.jpg}" src="../static/image/weixin.jpg" style="width: 120px">
              </div>
              <div class="image">
                <!--rounded bordered 是边线和圆角-->
                <img class="ui image rounded bordered" th:src="@{/images/zfb.jpg}" src="../static/image/zfb.jpg" style="width: 120px">
              </div>
            </div>
          </div>
        </div>
      </div>



    </div>



    <!--博客信息-->
    <div class="ui positive attached teal message">
      <!--grid进行左右布局-->
      <div class="ui middle aligned grid">
        <!--左边11份-->
        <div class="eleven wide column">
          <li>作者：<span th:text="${blog.user.nickname}">李仁密</span><a href="#" th:href="@{/about}" target="_blank">（联系作者）</a></li>
          <li>发表时间：<span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}">2017-10-02 09:08</span></li>
          <li>版权声明：自由转载-非商用-非衍生-保持署名（创意共享3.0许可证）</li>
          <li>公众号转载：请在文末添加作者公众号二维码</li>
        </div>
        <!--右边5份-->
        <div class="five wide column">
          <!-- right floated 往右浮动-->
          <img src="../static/image/微信名片.png" th:src="@{/images/avatar.png}" class="ui bordered rounded image right floated" style="width: 110px">
        </div>
      </div>
    </div>


    <!--留言信息-->
    <div class="ui attached bottom segment" th:if="${blog.commentabled}">
      <div id="comment-container"  class="ui teal segment">
        <div th:fragment="commentList">
          <div class="ui threaded comments" style="max-width: 100%;">
            <h3 class="ui dividing header">评论</h3>
            <div class="comment" th:each="comment : ${comments}">
              <a class="avatar">
                <img src="https://unsplash.it/100/100?image=1005" th:src="@{${comment.avatar}}">
              </a>
              <div class="content">
                <a class="author" >
                  <span th:text="${comment.nickname}">Matt</span>
                  <div class="ui mini basic teal left pointing label" th:if="${comment.nickname}=='Glorysun'">博主</div>
                  <!--<div class="ui mini basic teal left pointing label m-padded-mini" th:if="${comment.adminComment}">博主</div>-->
                </a>
                <div class="metadata">
                  <span class="date" th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                </div>
                <div class="text" th:text="${comment.content}">
                  How artistic!
                </div>
                <div class="actions">
                  <a class="reply" data-commentid="1" data-commentnickname="Matt" th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}" onclick="reply(this)">回复</a>
                </div>
              </div>

              <!-- 层级评论 -->
              <div class="comments" th:if="${#arrays.length(comment.replyComments)}>0">
              <div class="comment" th:each="reply : ${comment.replyComments}">
                <a class="avatar">
                  <img src="https://unsplash.it/100/100?image=1005" th:src="@{${reply.avatar}}">
                </a>
                <div class="content">
                  <a class="author" >
                    <span th:text="${reply.nickname}">Matt</span>
                    <div class="ui mini basic teal left pointing label" th:if="${reply.nickname}=='Glorysun'">博主</div>
                    &nbsp;
                    <span th:text="|@  ${reply.parentComment.nickname}|" class="m-teal">@ 小白</span>
                    <div class="ui mini basic teal left pointing label" th:if="${reply.parentComment.nickname}=='Glorysun'">博主</div>
                  </a>
                  <div class="metadata">
                    <span class="date" th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                  </div>
                  <div class="text" th:text="${reply.content}">
                    How artistic!
                  </div>
                  <div class="actions">
                    <a class="reply" data-commentid="1" data-commentnickname="Matt" th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}" onclick="reply(this)">回复</a>
                  </div>
                </div>

              </div>
              </div>


            </div>

          </div>
        </div>
      </div>
      <!-- 回复 -->
      <form id="blog-form" action="#" th:action="@{/comments}" method="post" class="ui form">
        <div id="comment-form" class="ui form">
          <input type="hidden" name="blogId" th:value="${blog.id}">
          <input type="hidden" name="parentCommentId" value="-1">
          <div class="field">
            <textarea name="content" placeholder="请输入评论信息..."></textarea>
          </div>
          <div class="fields">
            <div class="field m-mobile-wide m-margin-bottom-small">
              <div class="ui left icon input">
                <i class="user icon"></i>
                <input type="text" name="nickname" placeholder="姓名">
              </div>
            </div>
            <div class="field m-mobile-wide m-margin-bottom-small">
              <div class="ui left icon input">
                <i class="mail icon"></i>
                <input type="text" name="email" placeholder="邮箱">
              </div>
            </div>
            <div class="field  m-margin-bottom-small m-mobile-wide">
              <button id="commentpost-btn" type="submit" class="ui teal button m-mobile-wide"><i class="edit icon"></i>发布</button>
            </div>
          </div>

        </div>
      </form>

    </div>


  </div>

</div>

<!--右下角浮动的图标-->
<div class="m-padded m-right-bottom m-fixed">
  <div class="ui vertical icon buttons">
    <button type="button" class="ui teal toc button">目录</button>
    <a href="#comment-container" class="ui teal button">留言</a>
    <a href="#" class="ui teal icon button"><i class="chevron up icon"></i> </a>
  </div>
</div>
<!--目录-->
<div class="ui toc-container flowing popup transition hidden" style="width: 250px">
  <ol class="js-toc">

  </ol>
</div>

</div>

<br>
<br>
<!--底部footer-->
<footer th:replace="_fragments :: footer" class="ui inverted vertical segment m-padded-tb-massive">

</footer>


<!--/*/<th:block th:replace="_fragments :: script">/*/-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="../static/lib/prism/prism.js"></script>
<script src="../static/lib/tocbot/tocbot.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
<script src="https://cdn.bootcss.com/showdown/1.3.0/showdown.min.js"></script>
<!--/*/</th:block>/*/-->

<script>


  $('.menu.toggle').click(function () {
    $('.m-item').toggleClass('m-mobile-hide');
  });
  $("#reward").popup({
    popup : $(".pay"),
    on: 'click',
    position : 'bottom center'
  });

  tocbot.init({
    // Where to render the table of contents.
    tocSelector: '.js-toc',
    // Where to grab the headings to build the table of contents.
    contentSelector: '.js-toc-content',
    // Which headings to grab inside of the contentSelector element.
    headingSelector: 'h1, h2, h3',
  });

  $('.toc.button').popup({
    popup : $(".toc-container.popup"),
    on: 'click',
    position : 'left center'
  });


  //评论表单验证
  $('.ui.form').form({
    fields: {
      title: {
        identifier: 'content',
        rules: [{
          type: 'empty',
          prompt: '请输入评论内容'
        }
        ]
      },
      content: {
        identifier: 'nickname',
        rules: [{
          type: 'empty',
          prompt: '请输入你的昵称'
        }]
      },
      type: {
        identifier: 'email',
        rules: [{
          type: 'email',
          prompt: '请填写正确的邮箱地址'
        }]
      }
    }
  });



  //校验
  $('#commentpost-btn').click(function () {
    var boo = $('.ui.form').form('validate form');
    if (boo) {
      console.log('校验成功');
      postData();
    } else {
      console.log('校验失败');
    }
  });

  function postData(){
    $.ajax({
      url:"${pageContext.request.contextPath}/comments",
      method:"post",
      data:{
        "blogId":$("#blogId").val(),
        "nickname":$("#nickname").val(),
        "email":$("#email").val(),
        "content":$("#content").val(),
        "parentCommentId":$("#parentCommentId").val()
      },
      success:function(response){
        $(window).scrollTo($('#comment-container'),500);
        clearContent();
      },
      error:function(){
        console.log("请求发送失败..")
      }
    });
  }

  function clearContent() {
    $("[name='content']").val('');
    $("[name='parentCommentId']").val(-1);
    $("[name='content']").attr("placeholder", "请输入评论信息...");
  }

  function reply(obj) {
    var commentId=$(obj).data('commentid');
    var commentNickname=$(obj).data('commentnickname');
    $("[name='content']").attr("placeholder","@"+commentNickname).focus();
    $("[name='parentCommentId']").val(commentId);
    $(window).scrollTo($('#comment-form'),500);
  }


</script>



</body>
</html>
